package part7;

/**
 * @author wcj
 * @Date 2021/5/15 15:46
 * @Version 1.0
 */
public class Part78 extends Car {

    public Part78(String name) {
        super(name);
    }

    public void change(String name) {
        setName(name);
    }

    @Override
    public String toString() {
        return "Part78{}" + super.toString();
    }

    public static void main(String[] args) {
        Part78 bmw = new Part78("BMW");
        System.out.println(bmw);
        bmw.change("aodi");
        System.out.println(bmw);
    }
}

class Car {
    private String name;

    /**
     * protected适用于不想将其属性对全部人暴露而是只对其导出类暴露
     * 但是需要注意属性一般还是设置为private，符合封装的特性，我们可以提供protected供导出类进行操作
     *
     * @param name
     */
    protected void setName(String name) {
        this.name = name;
    }

    public Car(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                '}';
    }
}
